package com.herench.bs.handler;

import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import com.herench.bs.utils.DesUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
 * Created by ThinkPad on 2018/3/8.
 */

@Component
@Handler(code = "101103" ,name="二维码获取")
public class QRCodeRequestHandler extends AbstractMessageHandler {
    
    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String reqString = requestMessage.getArgsPropertyStringValue("reqString");
        String encodeType = requestMessage.getArgsPropertyStringValue("encodeType");
        Assert.isTrue(StringUtils.hasLength(channelCode), "channelCode 不能为空.");
        Assert.isTrue(StringUtils.hasLength(reqString), "reqString 不能为空.");
        Assert.isTrue(StringUtils.hasLength(encodeType), "encodeType 不能为空.");
        String resultString = null;
        String text = null;
        if (EncodeType.ID_CARD.getType().equals(encodeType)){
            resultString = DesUtil.encrypt(reqString);
            text = "患者请扫描二维码读取身份证号信息";
        }else if (EncodeType.RECORD_ID.getType().equals(encodeType)){
            resultString = DesUtil.encrypt(reqString);
            text = "患者请扫描二维码读取订单号信息";
        }else if (EncodeType.PAY_SEQ.getType().equals(encodeType)){
            resultString = DesUtil.encrypt(reqString);
            text = "患者请扫描二维码读取诊间缴费信息";
        }
        responseMessage.setDataAttribute("resultString", resultString);
        responseMessage.setDataAttribute("text", text);
        responseMessage.setCode("0");
        responseMessage.setMessage("请求成功");
        return responseMessage;
    }


    enum EncodeType {

        ID_CARD("1","身份证"),RECORD_ID("2","订单号"),PAY_SEQ("3","支付序号");

        private String type ;
        private String name;

        EncodeType(String type, String name) {
            this.type = type;
            this.name = name;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
